<?php
class Resource{

	const MES_ER_INSERT_EXIST = 'mes_er_insert_exist';
	const MES_ER_INSERT_COL_EXIST = 'mes_er_insert_col_exist';
	const MES_ER_UPDATE_NON = 'mes_er_update_non';
	
	private $_resourceArray;
	private static $_instance;
	private $_resourcePath;
	private $_type;
	
	private function __construct($type = null){
		if($type == null){
			$this->_type = Configuration::RESOURCE_DEFAULT;
		}
		else{
			$this->_type = $type;
		}
		$this->_resourcePath = RESOURCE_PATH . SLASH . $this->_type . Configuration::RESOURCE_DEFAULT_EXT;
		if(!file_exists($this->_resourcePath)){
			Log::error("Resource", "Resource " . $this->_resourcePath . ' not found!');
			if(Configuration::DEBUG_MOD)
				throw new ResourceException("Resource " . $this->_resourcePath . ' not found!');
			$this->_resourcePath = RESOURCE_PATH . SLASH . Configuration::RESOURCE_DEFAULT . Configuration::RESOURCE_DEFAULT_EXT;
		}
		$this->_resourceArray = parse_ini_file($this->_resourcePath);
	}
	/**
	 * 
	 * Get Resource Instance.
	 * @param String $type
	 * @return Resource
	 */
	public static function getInstance($type = null){
		if(!self::$_instance||$type != $this->_type){
			self::$_instance = new Resource($type);
		}
		return self::$_instance;
	}
	/**
	 * Get Resource String ...
	 * @param String $name
	 */
	public function getResource($name){
		return (isset($this->_resourceArray[$name]))?$this->_resourceArray[$name]:STRING_EMPTY;
	}
}